<?php

//get all order	
function getAllOrder(){
	$qr ="SELECT * FROM `order`";
	return mysql_query($qr);
}

//add order	
function addOrder($customerID,$orderMonth,$orderYear,$productNumberTotal,$orderAmountTotal){
	$qr ="INSERT INTO `order`(CustomerID,OrderMonth,OrderYear,ProductNumberTotal,OrderAmountTotal) VALUES('$customerID','$orderMonth','$orderYear','$productNumberTotal','$orderAmountTotal')";
	mysql_query($qr);
	return mysql_insert_id();
}

//get order by id	
function getOrderByID($caseID){
	$qr ="SELECT * FROM `order` WHERE CaseID = $caseID;";
	return mysql_query($qr);
}

//delete order	
function deleteOrder($orderID){
	$qr ="DELETE FROM `order` WHERE OrderID = $orderID; ";
	mysql_query($qr);
}

//revenue total 
function getRevenueTotal(){
	$qr ="SELECT SUM( OrderAmountTotal ) AS  `RevenueTotal` 
FROM  `order`; ";
	$revenueTotal = mysql_fetch_array(mysql_query($qr));	
	return $revenueTotal['RevenueTotal']/1000000;
}

//revenue by year 
function getRevenueByYear($year){
	$qr ="SELECT SUM( OrderAmountTotal ) AS  `YearRevenue` 
FROM  `order` 
WHERE OrderYear =$year; ";
	$yearRevenue = mysql_fetch_array(mysql_query($qr));	
	return $yearRevenue['YearRevenue']/1000000;
}

//revenue by month of year 
function getRevenueByMonthOfYear($year,$month){
	$qr ="SELECT SUM( OrderAmountTotal ) AS  `MonthRevenue` 
FROM  `order` 
WHERE OrderYear =$year AND OrderMonth = $month; ";
	$monthRevenue = mysql_fetch_array(mysql_query($qr));	
	return $monthRevenue['MonthRevenue']/1000000;
}


?>